//
//  KHDBHelper.m
//  AMapDemo-iOS
//
//  Created by apang on 2017/12/20.
//  Copyright © 2017年 men.apang.AMapDemo-iOS. All rights reserved.
//

#import "KHDBHelper.h"
#import <FMDB/FMDB.h>
static KHDBHelper *dbHelper = nil;
@interface KHDBHelper()
@end
@implementation KHDBHelper
@synthesize dbQueue = _dbQueue,dbPath=_dbPath;
+ (instancetype)shareInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        dbHelper = [[KHDBHelper alloc] init];
    });
    return dbHelper;
}

- (void)changeDBFileWithFullFilePath:(NSString *)fullDBPath {
    if (_dbQueue) {
        _dbQueue = nil;
    }
    _dbPath = fullDBPath;
    _dbQueue = [[FMDatabaseQueue alloc] initWithPath:_dbPath];
}
- (instancetype)init {
    if (self = [super init]) {
        NSString *document = [NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        _dbPath = [document stringByAppendingPathComponent:@"sqlite3.db"];
    }
    return self;
}
-(FMDatabaseQueue *)dbQueue {
    if (!_dbQueue) {
        _dbQueue = [[FMDatabaseQueue alloc] initWithPath:_dbPath];
    }
    return _dbQueue;
}
@end
